package com.atguigu.lease.web.admin.custom.config;

import com.atguigu.lease.web.admin.custom.interceptor.AuthenticationInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author 张智勇
 * @date 2025年08月16日 11:40
 */

//配这个配置能查到？
@Configuration
public class WebMvcConfiguration implements WebMvcConfigurer {

    @Autowired
    StringToBaseEnumConverterFactory stringToBaseEnumConverterFactory;

//    @Autowired  (这个配置重要，要学会，理解)
//    stringToItemTypeConverter stringToItemTypeConverter;

    @Autowired
    private AuthenticationInterceptor authenticationInterceptor;

    @Value("${admin.auth.path-patterns.include}")  //这里的命名有要求么？？
    private String[] includePathPatterns;

    @Value("${admin.auth.path-patterns.exclude}")
    private String[] excludePathPatterns;
    @Override
    public void addFormatters(FormatterRegistry registry) {
         //特定的转换器
//        registry.addConverter(stringToItemTypeConverter);
        //通用的转换器
        registry.addConverterFactory(stringToBaseEnumConverterFactory);

    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(authenticationInterceptor)
                .addPathPatterns(includePathPatterns)
                .excludePathPatterns(excludePathPatterns);
    }
}
